package com.qilu.domain;

import java.util.HashMap;

public class R extends HashMap<String,Object> {
    /** 状态码 */
    private static final String CODE_TAG = "code";

    /** 返回内容 */
    private static final String MSG_TAG = "msg";

    /** 数据对象 */
    private static final String DATA_TAG = "data";

    public static R success(String msg,Object data){
        return new R().put(CODE_TAG,200).put(MSG_TAG,msg).put(DATA_TAG,data);
    }

    public static R success(String msg){
        return new R().put(CODE_TAG,200).put(MSG_TAG,msg);
    }
    public static R success(Object data){
        return new R().put(CODE_TAG,200).put(MSG_TAG,"操作成功").put(DATA_TAG,data);
    }

    public static R success(){
        return new R().put(CODE_TAG,200).put(MSG_TAG,"操作成功");
    }

    public static R error(Integer code,String msg,Object data){
        return new R().put(CODE_TAG,code).put(MSG_TAG,msg).put(DATA_TAG,data);
    }

    public static R error(Integer code,String msg){
        return new R().put(CODE_TAG,code).put(MSG_TAG,msg);
    }


    public static R error(String msg){
        return new R().put(CODE_TAG,500).put(MSG_TAG,msg);
    }


    /**
     * 支持链式编程
     * @param key
     * @param value
     * @return
     */
    @Override
    public R put(String key, Object value)
    {
        super.put(key, value);
        return this;
    }

}